package org.jjj.org.service.impl;

import org.jjj.basic.utils.BaiduAuditUtils;
import org.jjj.basic.utils.ResultAjax;
import org.jjj.org.service.IBaiduAiService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

@Service
public class BaiduAiServiceImpl implements IBaiduAiService {
    /**
     * 自动审核类
     * @param text 文本
     * @param imgUrl 图片
     * @param videoUrl 视频
     * @return
     */
    @Override
    public ResultAjax audit(String text, String imgUrl, String videoUrl) {
        //默认返回成功
        ResultAjax result = ResultAjax.me();
        StringBuilder stringBuilder = new StringBuilder();
        //判断文本信息是否合规
        if (!StringUtils.isEmpty(text)) {
            Map<String, Object> textAuditResult = BaiduAuditUtils.TextCensor(text);
            Boolean success = (Boolean) textAuditResult.get("success");
            String message = (String) textAuditResult.get("message");
            //如果不合规
            if (!success){
                result.setSuccess(false);
                stringBuilder.append(text+"不合规原因:"+message);
            }
        }

        if (!StringUtils.isEmpty(imgUrl)) {
            Map<String, Object> imgAuditResult =
                    BaiduAuditUtils.ImgCensor(imgUrl);
            Boolean success = (Boolean) imgAuditResult.get("success");
            String message = (String) imgAuditResult.get("message");
            if (!success){
                result.setSuccess(false);
                stringBuilder.append(imgUrl+"不合规原因:"+message);
            }
        }
        if (!StringUtils.isEmpty(videoUrl)) {
            //@TODO
        }
        //当前面result.setSuccess(false)时进入if
        if (!result.getSuccess()){
            result.setMessage(stringBuilder.toString());
        }
        return result;
    }
}
